//
//  TestController.m
//  Test
//
//  Created by 红沙尘 on 17/6/8.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "TestController.h"
#import "TestCell.h"

@interface TestController ()<UITableViewDataSource,UITableViewDelegate>
{
    __weak IBOutlet UITableView *myTableView;
    
    NSMutableArray *dataArray;
}
@end

@implementation TestController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    dataArray = @[].mutableCopy;
    
    for (int i = 0; i < 50; i ++) {
        
        [dataArray addObject:@{@"a":@"b"}];
    }
    
    [myTableView registerNib:[UINib nibWithNibName:@"TestCell" bundle:nil]
      forCellReuseIdentifier:@"TestCell"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    TestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TestCell"];
    
    [cell loadWithDict:dataArray[indexPath.row]];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    TestCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell updateSelectedState];
}
- (IBAction)close:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
